<template>
    <div class="bx-editor">
        <van-nav-bar
                title="新增员工"
                left-text="返回"
                left-arrow
                border
                fixed
                @click-left="$router.go(-1)"
        />
        <div style="height:50px"></div>
        <div class="title">
            投保信息
        </div>
        <div>
            <van-cell-group>
                <van-field v-model="realname" label="姓名" placeholder="请填写投保人姓名" size="large" required />
                <van-field v-model="mobile" label="手机号" placeholder="请填写手机号" size="large" required />
                <van-field v-model="certificate_code" label="身份证号" placeholder="请填写身份证号" size="large" required />
                <van-field v-model="certificate_type" label="工种" placeholder="请填写工种信息" size="large" required />
                <van-field v-model="remark" rows="3" autosize label="备注" type="textarea" placeholder="请输入备注信息" show-word-limit />
            </van-cell-group>
        </div>

        <div class="foot-btn">
            <div class="blue-btn" @click="pushInfo">保存</div>
        </div>

        <div style="height: 10vh;"></div>
    </div>
</template>

<script>

export default {
    name: "kfAddStaff",
    components: {},
    data() {
        return {
            realname: '',
            certificate_code: '',
            mobile: '',
            certificate_type: '',
            remark: '',

            userId: '',
        }
    },
    methods: {
        pushInfo() {
            let params = {
                wx_member_id: localStorage.getItem('wx_member_id'),
                token: localStorage.getItem('token'),
                opmode: 'add',
                cate_id: 1,
                member_goods_id: this.$route.query.goodsId,


                realname: this.realname, //姓名
                certificate_code: this.certificate_code, //身份证号
                mobile: this.mobile, //手机号
                certificate_type: this.certificate_type, //工种
                remark: this.remark, //备注
            };
            let url = ''
            if (this.$route.query.type == 'set') {
                params.opmode = 'edit'
                params.id = this.$route.query.userId
                params.oid = this.$route.query.oid
                url = '/api/order_detail_roster/edit'
            } else {
                params.orderid = this.$route.query.oid
                url = '/api/order_detail_roster/add'
            }

            this.$post(url, params)
                .then(res => {
                    if (res.code == 1) {
                        this.$Toast(res.msg);
                        if (this.$route.query.type == 'set') {
                            setTimeout(() => {
                                this.$router.go(-1)
                            }, 1500);
                            return;
                        }
                        this.realname = ''
                        this.certificate_code = ''
                        this.mobile = ''
                        this.certificate_type = ''
                        this.remark = ''
                        this.$Toast(res.msg);
                        setTimeout(() => {
                            this.$router.go(-1)
                        }, 1500);

                    } else {
                        this.$Toast(res.msg);
                    }
                })
                .catch(err => { });
        },
        getUserInfo() {
            let params = {
                wx_member_id: localStorage.getItem('wx_member_id'),
                token: localStorage.getItem('token'),
                id: this.$route.query.userId,



            };
            this.$post("/api/order_detail_roster/read", params)
                .then(res => {
                    if (res.code == 1) {

                        this.realname = res.data.realname
                        this.certificate_code = res.data.certificate_code
                        this.mobile = res.data.mobile
                        this.certificate_type = res.data.certificate_type
                        this.remark = res.data.remark
                        this.$Toast(res.msg);
                    } else {
                        this.$Toast(res.msg);
                    }
                })
                .catch(err => { });
        }

    },
    created() {
        if (this.$route.query.type == 'set') {
            this.getUserInfo()

        }
    },
}
</script>

<style scoped lang="less">
.foot-btn {
    padding-bottom: 80px;
    display: flex;
    justify-content: center;
    align-items: center;
}
</style>